﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common.model.enumer;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.activities
{
    /// <summary>
    /// 世界军团
    /// </summary>
    class WorldArmyServer : LogicServer
    {
        public WorldArmyServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_WorldArmy; ServerReadableName = ConfigStrings.SR_WorldArmy; }
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            frm.chk_world_army_enable.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");
            if (conf.ContainsKey(ConfigStrings.boxtype))
            {
                int boxtype = 0;
                Int32.TryParse(conf[ConfigStrings.boxtype], out boxtype);
                if (boxtype < 0 || boxtype >= frm.combo_world_army_boxtype.Items.Count) boxtype = 0;
                frm.combo_world_army_boxtype.SelectedIndex = boxtype;
            }
            else frm.combo_world_army_boxtype.SelectedIndex = 0;

            if (conf.ContainsKey(ConfigStrings.refresh))
            {
                int refresh_type = 0;
                Int32.TryParse(conf[ConfigStrings.refresh], out refresh_type);
                if (refresh_type < 0 || refresh_type >= frm.combo_world_army_refresh_type.Items.Count) refresh_type = 0;
                frm.combo_world_army_refresh_type.SelectedIndex = refresh_type;
            }
            else frm.combo_world_army_refresh_type.SelectedIndex = 0;

            frm.chk_world_army_buybox1.Checked = conf.ContainsKey(ConfigStrings.buybox1) && conf[ConfigStrings.buybox1].ToLower().Equals("true");
            frm.chk_world_army_buybox2.Checked = conf.ContainsKey(ConfigStrings.buybox2) && conf[ConfigStrings.buybox2].ToLower().Equals("true");
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_world_army_enable.Checked.ToString());
            int boxtype = frm.combo_world_army_boxtype.SelectedIndex;
            if (boxtype < 0) boxtype = 0;
            conf.setConfig(ServerName, ConfigStrings.boxtype, boxtype.ToString());
            int refresh_type = frm.combo_world_army_refresh_type.SelectedIndex;
            if (refresh_type < 0) refresh_type = 0;
            conf.setConfig(ServerName, ConfigStrings.refresh, refresh_type.ToString());
            conf.setConfig(ServerName, ConfigStrings.buybox1, frm.chk_world_army_buybox1.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.buybox2, frm.chk_world_army_buybox2.Checked.ToString());
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.boxtype, "0");
            conf.setConfig(ServerName, ConfigStrings.refresh, "0");
            conf.setConfig(ServerName, ConfigStrings.buybox1, "false");
            conf.setConfig(ServerName, ConfigStrings.buybox2, "false");
            renderSettings();
        }
    }
}
